package com.qidianit.task.controller;

import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.pojo.QdResult;
import com.qidianit.task.vo.ProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @Author 钟思念
 * @Company
 * @Description
 * @Time 2024/9/5 22:01
 */
@RestController
@RequestMapping("/project")
@CrossOrigin
public class ProjectController {
    @Autowired
    private ProjectService projectService;
    // 这里没有使用@RequestBody
    @GetMapping("/list")
    public QdResult list(Project project, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        return projectService.selectByPage(project,page,limit);
    }
    //通过id查询项目信息
    @GetMapping("/queryById")
    public  QdResult queryById(@RequestParam String projectId){
        return  projectService.selectById(projectId);
    }
    //通过编辑更新项目数据
    @PostMapping("/update")
    public QdResult updateProject(@RequestBody Project project){
        return projectService.updateProject(project);
    }
    //通过id更新项目状态使其逻辑删除
    @PostMapping("/delete")
    public QdResult delete(@RequestParam String projectId){
        return projectService.deleteProject(projectId);
    }
    //通过id更新项目状态使其归档
    @PostMapping("/pigeonhole")
    public QdResult pigeonhole(@RequestParam String projectId){
        return projectService.pigeonholeProject(projectId);
    }
    //通过接收集合projectIds进行批量删除（批量更新项目状态）
    @PostMapping("/batchDelete")
    public QdResult batchDelete(@RequestBody ProjectVo vo){
        System.out.println(vo);
        return projectService.deleteBySelect(vo.getProjectIds());
        //return QdResult.success();
    }
    //通过接收集合projectIds进行批量归档（批量更新项目状态）
    @PostMapping("/batchPigeonhole")
    public QdResult batchPigeonhole(@RequestBody ProjectVo vo){
       // System.out.println(Arrays.toString(projectIds));
        return projectService.pigeonholeBySelect(vo.getProjectIds());
       // return QdResult.success();
    }
    //通过接收集合projectIds进行批量发布 （批量更新项目状态）
    @PostMapping("/batchPublish")
    public QdResult  batchPublish(@RequestBody ProjectVo vo){
        return projectService.publishBySelect(vo.getProjectIds());
    }
    //查询删除列表
    @GetMapping("/deleteList")
    public QdResult deleteList(Project project, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10")int limit){
        return projectService.selectDeleteByPage(project,page,limit);
    }
    //归档列表中行功能的删除列表、
    @PostMapping("/draft")
    public QdResult draftPigeonholeList(@RequestParam String projectId){
        return projectService.draftById(projectId);
    }

    //统计全部的项目数量
    @GetMapping("/allProjects")
    public QdResult allProjects(){
        return projectService.allProject();
    }
    //统计我的全部项目
    @GetMapping("/myProjects")
    public QdResult myProjects(@RequestParam Long userId){
        return projectService.myAllProject(userId);
    }

}
